package org.example.web.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
public class UserController {
    Logger logger = LoggerFactory.getLogger(UserController.class);
    @Autowired
    ObjectMapper objectMapper;

    @RequestMapping("/user")
    public Object getUser() throws JsonProcessingException {
        Map<String, Object> data = loadData();
        logger.info(objectMapper.writeValueAsString(data));
        return data;
    }

    private Map<String, Object> loadData() {
        Map<String, Object> data = new HashMap<>();
        data.put("id", 1001L);
        data.put("name", "张三");
        data.put("url", "http://www.bing.com");
        data.put("createTime", new Date());
        data.put("hobbies", new String[]{"Basketball", "Football", "Pingpang"});
        return data;
    }
}
